package com.example.demo.common.util;

import org.apache.commons.io.IOUtils;

import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

public class DownUrlUtil {
    public static byte[] download(String _url) throws Exception {
        URL url = new URL(_url);
        URLConnection con = url.openConnection();
        con.setConnectTimeout(5000);
        InputStream is = con.getInputStream();
        byte[] files = IOUtils.toByteArray(is);
        is.close();
        return files;
    }

//    public static void main(String[] args) throws Exception {
//        Long time = System.currentTimeMillis();
////        System.out.println(new Date().getTime());
//        String url = "http://kaiban-test.oss-cn-beijing.aliyuncs.com/2021-05-07/61AFB3E6433E4401B0FE776F65F6FD94.jpg?Expires=1935733492&OSSAccessKeyId=LTAI5tL6vVxitCJLcWqFaof8&Signature=t5lX4qsjp11F%2FK3J78gOUGAm%2Fes%3D";
//        byte[] files = download(url);
//        System.out.println(files.length/1024/1024.0);
//        File file = new File("D:\\1.jpg");
//        OutputStream os = new FileOutputStream(file);
//        os.write(files);
//        os.close();
//        Long time1 = new Date().getTime();
//        System.out.println(time1-time);
//    }
}
